<template>
<div>
  <el-row :gutter="10" style="margin-bottom: 60px">
    <el-col :span="6">
      <el-card style="color: #409EFF">
        <div style="font-weight: bold"><i><el-icon><Avatar /></el-icon></i>用户总数</div>
        <div style="padding: 10px 0;text-align: center;font-weight: bold">{{ totalUsers }}人</div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card style="color: #F56C6C">
        <div style="font-weight: bold"><i><el-icon><Shop /></el-icon></i>订单总量</div>
        <div style="padding: 10px 0;text-align: center;font-weight: bold">{{ totalOrders }}条</div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card style="color: #67C23A">
        <div style="font-weight: bold"><i><el-icon><Money /></el-icon></i>题库数量</div>
        <div style="padding: 10px 0;text-align: center;font-weight: bold">{{ totalQbank }}题</div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card style="color: #E6A23C">
        <div style="font-weight: bold"><i><el-icon><Notebook /></el-icon></i>商品总数</div>
        <div style="padding: 10px 0;text-align: center;font-weight: bold">{{ totalGoods }}本</div>
      </el-card>
    </el-col>
  </el-row>
  <el-row :gutter="30" style="margin-top: 50px">
    <el-col :span="12">
      <el-card>
        <div id="main" style="width: 500px;height: 400px"></div>
      </el-card>
    </el-col>
    <el-col :span="12">
      <el-card>
        <div id="pie" style="width: 500px;height: 400px" ></div>
      </el-card>
    </el-col>
  </el-row>
</div>
</template>

<script>
import * as echarts from 'echarts'
import request from "@/utils/request";
import {Notebook,Money,Shop,Avatar} from '@element-plus/icons-vue'
export default {
  name: "Home",
  components:{
    Notebook,Money,Shop,Avatar
  },
  created() {
    this.load()
  },
  mounted() {


    let  option = {
      title: {
        text:"各个季度书本销量",
        subtext: "趋势图",
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: ['第一季度','第二季度','第三季度','第四季度']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        }
      ]
    };
    let  chartDom = document.getElementById('main');
    let  myChart = echarts.init(chartDom);




    //饼图
    let pieOption = {
      title: {
        text:"各个季度书本销量",
        subtext: "比列图",
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '70%',
          label:{
            normal:{
              show:true,
              position:'inner',
              textStyle:{
                fontWeight:300,
                fontSize:16,
                color:'#fff'
              },
              formatter:'{d}%'
            }
          },
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    let  pieDom = document.getElementById('pie');
    let  pieChart = echarts.init(pieDom);

    request.get("/echarts/members").then(res =>{
      // option.xAxis.data=res.data.x
      option.series[0].data=res.data
      option.series[1].data=res.data

      myChart.setOption(option)

      pieOption.series[0].data =[
        {name:"第一季度",value:res.data[0]},
        {name:"第二季度",value:res.data[1]},
        {name:"第三季度",value:res.data[2]},
        {name:"第四季度",value:res.data[3]},
      ]

      pieChart.setOption(pieOption);
    })
  },
  data(){
    return{
      totalUsers:"",
      totalGoods:"",
      totalQbank:"",
      totalOrders:""
    }
  },
  methods:{
    load() {
      request.get("/user").then(res => {
        this.totalUsers = res.total
      });
      request.get("/orders").then(res => {
        this.totalOrders = res.total
      });
      request.get("/qbank").then(res => {
        this.totalQbank = res.total
      });
      request.get("/goods").then(res => {
        this.totalGoods = res.total
      })
    },
  }
}
</script>

<style scoped>

</style>